#include "bot.h"
#include "defines.h"
using namespace std;

// constructor
bot::bot(wxInt32 stic, superBot *mySbot, int nhealth) {
  int i;
  direction = rand() % 4;
  startTic = stic;
  mySuperbot = mySbot;
  lineNr = 0;
  health = nhealth;
  // load the programming code
  code.readfile(mySuperbot->codeFile);
  // clear memory (set to 0)
  for(i = 0; i < BOT_NUMMEMCELLS; i++)
    memory[i] = 0;
}

superBot::superBot(wxInt32 sbotid, long tic) {
  superBotId = sbotid;
  for(int i = 0; i < tic; i++)
    numbers.push_back(0);
}

void superBot::ReadNameFromFile() {
  wxTextFile *file = new wxTextFile(codeFile);
  if (file->Exists()) {
    if (!file->IsOpened()) {
      file->Open();
      // get the name of the superbot (first line)
      wxString str = file->GetFirstLine();
      name = str;
    }
  } else {
    wxMessageBox(wxString::Format(_("The file \"%s\" could not be opened!"), codeFile.c_str()), _("Error"), wxICON_ERROR);
  }
}
